<!DOCTYPE html>
<html>
<head>
	 <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>上传文件</title>
    <link href="css/iconfont.css" rel="stylesheet" type="text/css"/>
    <link href="css/fileUpload.css" rel="stylesheet" type="text/css">
    <style>
        body, html{font-family: PingFangSC-Regular, sans-serif;}
        body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td { margin:0; padding:0; }
        body, button, input, select, textarea { font:12px/1.5tahoma, arial, \5b8b\4f53; }
        h1, h2, h3, h4, h5, h6{ font-size:100%; }
        address, cite, dfn, em, var { font-style:normal; }
        code, kbd, pre, samp { font-family:couriernew, courier, monospace; }
        small{ font-size:12px; }
        ul, ol { list-style:none; }
        a { text-decoration:none; }
        a:hover { text-decoration:underline; }
        sup { vertical-align:text-top; }
        sub{ vertical-align:text-bottom; }
        legend { color:#000; }
        fieldset, img { border:0; }
        button, input, select, textarea { font-size:100%; }
        table { border-collapse:collapse; border-spacing:0; }
        
        .fileUploadContent{
            padding: 20px;
        }

    </style>
</head>
<body>
    <div id="fileUploadContent" class="fileUploadContent"></div>
    <br/>
    <button onclick="testUpload()">函数提交</button>
    <button id="selfUploadBt">设定id提交</button>
    <button onclick="tt()">显示错误</button>
    <br/>
    </body>

    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.4.4.min.js"></script>
    <script type="text/javascript" src="js/fileUpload.js"></script>
    <script type="text/javascript">

    //     $.ajax({
    //     type: 'GET',
    //     url: "http://api.tuntun.roc.ltd/adm/aliyun/oss/sts/upload/token/for/admin",
    //     contentType: 'application/json',
    //     withCredentials: true,
    //     dataType: 'json',
    //     success: function(data){
    //         console.log(data);
            
    //     },
    //     error: function(error) {
            
    //     }
    // })
    
        $("#fileUploadContent").initUpload({
            "uploadUrl":"#",//上传文件信息地址
            "progressUrl":"#",//获取进度信息地址，可选，注意需要返回的data格式如下（{bytesRead: 102516060, contentLength: 102516060, items: 1, percent: 100, startTime: 1489223136317, useTime: 2767}）
            "selfUploadBtId":"selfUploadBt",//自定义文件上传按钮id
            "isHiddenUploadBt":false,//是否隐藏上传按钮
            "isHiddenCleanBt":false,//是否隐藏清除按钮
            "isAutoClean":false,//是否上传完成后自动清除
            "velocity":10,//模拟进度上传数据
            //"rememberUpload":true,//记住文件上传
           // "showFileItemProgress":false,
            //"showSummerProgress":false,//总进度条，默认限制
            //"scheduleStandard":true,//模拟进度的方式，设置为true是按总进度，用于控制上传时间，如果设置为false,按照文件数据的总量,默认为false
            //"size":350,//文件大小限制，单位kb,默认不限制
            //"maxFileNumber":3,//文件个数限制，为整数
            //"filelSavePath":"",//文件上传地址，后台设置的根目录
            //"beforeUpload":beforeUploadFun,//在上传前执行的函数
            "onUpload":onUploadFun,//在上传后执行的函数
             //autoCommit:true,//文件是否自动上传
            //"fileType":['png','jpg','docx','doc']，//文件类型限制，默认不限制，注意写的是文件后缀
    
        });
    
        function beforeUploadFun(opt){
            opt.otherData =[{"name":"你要上传的参数","value":"你要上传的值"}];
        }
        function onUploadFun(opt,data){
            alert(data);
            uploadTools.uploadError(opt);//显示上传错误
        }
        function timestamp(){  
     var time = new Date();  
     var y = time.getFullYear();  
     var m = time.getMonth()+1;  
     var d = time.getDate();  
     var h = time.getHours();  
     var mm = time.getMinutes();  
     var s = time.getSeconds();  
     
     console.log(y);
   
     return ""+y+add0(m)+add0(d)+add0(h)+add0(mm)+add0(s);  
 }  
        function testUpload(){
            var opt = uploadTools.getOpt("fileUploadContent");
            uploadEvent.uploadFileEvent(opt);
            var file = opt.fileList[0];
            var storeAs = file.name;
            var val= file.val();
            var suffix = val.substr(val.indexOf("."));
            var obj=timestamp();  // 这里是生成文件名
            var storeAs = 'upload-file/'+"/"+obj+suffix;  //命名空间
            var client = new OSS.Wrapper({
                region: 'oss-cn-beijing',
                accessKeyId: 'STS.JQgePGyxEKu8gsnGxhnAqnHLb',
                accessKeySecret: 'EvDv6okdp5tMTUVSLXiBP8aJyUMYZbaMbyQxkQyH1yME',
                bucket: 'ttresource',
                stsToken: "CAIS9AF1q6Ft5B2yfSjIq5LSLurzlKdk/LfTZVXfo3g9Ys5dgY3ngDz2IHtMdHRgAukcsfgwmG5Z6Pwclq1vRoRZHa1bzgSrqsY5yxioRqacke7XhOV2pf/IMGyXDAGBr622Su7lTdTbV+6wYlTf7EFayqf7cjPQND7Mc+f+6/hdY88QQxOzYBdfGd5SPXECksIBMmbLPvvfWXyDwEioVRox4Vsl1TIhtf3nkpzBuyCz1gOqlrUnwK3qOYWhYsVWO5Nybsy4xuQedNCai3YAtkgRrf0p0PMYp2aZ5I+HekVN+RidNPfO+dAqMxV4eqUgC1nhHnh7SgkTGoABN6P/loZxCKY8zb77tXYgIUVzjYmWYX+M6ldYytj31cLveHD6HW5Wi8QAuUWg7wXq1ZH0ZsFwbCPNcypLUW/KtgeQH8KpUFpvyV801ABrYBDpbNUheG1UQzDmFheMqtbOOLrcwoExaSG3ZiFqCvXn1VASRyiBW8pha4LgmX2HsB0=",
              });
              client.multipartUpload(storeAs, file).then(function (result) {
                  console.log(result);
              }).catch(function (err) {
                  console.log(err);
              });
        }
        function tt() {
            var opt = uploadTools.getOpt("fileUploadContent");
            console.log(opt)
            uploadTools.uploadError(opt);//显示上传错误
        }
    </script>
</html>